<template>
  <div class="mass-attribute-info-content">
    <div class="mt-2" v-for="message in massAttributeMessageList">{{ message }}</div>

    <div class="mt-2">
      {{ $t('message.MassAttributeTool.' + massAttributeInfo.BaryCenter.name) + ':' }}
      {{ '(' + massAttributeInfo.BaryCenter.unit + ')' }}
    </div>
    <div v-for="message in baryCenterMessageList" class="pl-4">{{ message }}</div>

    <div class="mt-2">
      {{ $t('message.MassAttributeTool.axesAndMoments') }}
      {{ `( ${massAttributeInfo.T1.unit} ) ` }}
    </div>
    <div>{{ $t('message.MassAttributeTool.centerOfMass') }}</div>
    <div class="tw-flex">
      <div>
        <div v-for="message in inertiaMessageList.T1" class="pl-4">{{ message }}</div>
      </div>
      <div>
        <div v-for="message in inertiaMessageList.T2" class="pl-4">{{ message }}</div>
      </div>
    </div>

    <div class="mt-2">
      {{ $t('message.MassAttributeTool.momentsOfInertia') }}
      {{ `( ${massAttributeInfo.BT.unit} )` }}
    </div>
    <div>
      {{ $t('message.MassAttributeTool.centerOfMassAndAlignOutputCoordinateSystem') }}
    </div>
    <div class="tw-flex">
      <div>
        <div v-for="message in inertiaTensorByBaryCenterMessageList.x" class="pl-4">{{ message }}</div>
      </div>
      <div>
        <div v-for="message in inertiaTensorByBaryCenterMessageList.y" class="pl-4">{{ message }}</div>
      </div>
      <div>
        <div v-for="message in inertiaTensorByBaryCenterMessageList.z" class="pl-4">{{ message }}</div>
      </div>
    </div>
    <div class="mt-2">
      {{ $t('message.MassAttributeTool.momentsOfInertia') }}
      {{ ` ( ${massAttributeInfo.OT.unit} )` }}
    </div>
    <div>
      {{ $t('message.MassAttributeTool.outputCoordinateSystem') }}
    </div>
    <div class="tw-flex">
      <div>
        <div v-for="message in inertiaTensorByCoordinateSystemMessageList.x" class="pl-4">{{ message }}</div>
      </div>
      <div>
        <div v-for="message in inertiaTensorByCoordinateSystemMessageList.y" class="pl-4">{{ message }}</div>
      </div>
      <div>
        <div v-for="message in inertiaTensorByCoordinateSystemMessageList.z" class="pl-4">{{ message }}</div>
      </div>
    </div>
  </div>
</template>

<script>


import {massAttributeToolManager} from "./MassAttributeToolManager";

export default {
  name: "MassAttributeInfoContent",
  props: {
    massAttributeInfo: null,
  },
  methods: {
    attributeValue(item) {
      let name = item.name;
      let value = item.value;
      let unit = item.unit;
      // 这里不应该使用科学计数法以后的密度值判断，需根据内核返回的值进行判断
      if (name === 'Density' && item.different) {
        return "各不相同"
      }

      if (name === "Mass") {
        return massAttributeToolManager.massValue !== '' ? massAttributeToolManager.massValue + unit : value + unit;
      }
      return value + unit
    },
  },
  computed: {
    massAttributeMessageList() {
      let list = [];
      ['Density', 'Mass', 'Volume', 'Area'].forEach(item => {
        list.push(this.$t('message.MassAttributeTool.' + this.massAttributeInfo[item].name) + ' = ' + this.attributeValue(this.massAttributeInfo[item]))
      })
      return list
    },

    baryCenterMessageList() {
      let list = [];
      ['x', 'y', 'z'].forEach(item => {
        list.push(this.$t('message.MassAttributeTool.' + this.massAttributeInfo.BaryCenter[item].name) + ' = ' + this.massAttributeInfo.BaryCenter[item].value)
      })
      return list
    },

    inertiaMessageList() {
      let T1 = [];
      let T2 = [];
      ['x', 'y', 'z'].forEach(item => {
        T1.push(`L${item} = (` + this.massAttributeInfo.T1.value[`L${item}0`] + ', ' + this.massAttributeInfo.T1.value[`L${item}1`] + ', ' + this.massAttributeInfo.T1.value[`L${item}2`] + `)`)
        T2.push(`P${item} = ` + this.massAttributeInfo.T2.value[`P${item}`])
      })
      return {T1, T2}
    },

    inertiaTensorByBaryCenterMessageList() {
      let x = [];
      let y = [];
      let z = [];
      ['x', 'y', 'z'].forEach(item => {
        x.push(`L${item}x = ` + this.massAttributeInfo.BT.value[`L${item}x`])
        y.push(`L${item}y = ` + this.massAttributeInfo.BT.value[`L${item}y`])
        z.push(`L${item}z = ` + this.massAttributeInfo.BT.value[`L${item}z`])
      })
      return {x, y, z}
    },

    inertiaTensorByCoordinateSystemMessageList() {
      let x = [];
      let y = [];
      let z = [];
      ['x', 'y', 'z'].forEach(item => {
        x.push(`L${item}x = ` + this.massAttributeInfo.OT.value[`L${item}x`])
        y.push(`L${item}y = ` + this.massAttributeInfo.OT.value[`L${item}y`])
        z.push(`L${item}z = ` + this.massAttributeInfo.OT.value[`L${item}z`])
      })
      return {x, y, z}
    },
  },
}
</script>
<style scoped>
.mass-attribute-info-content div {
  white-space: nowrap;
}
</style>
